package com.android.minetopin.fragment.group;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.Paint;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.style.AbsoluteSizeSpan;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.android.minetopin.R;
import com.android.minetopin.activity.BaseObject;
import com.android.minetopin.activity.MainRecommendType;
import com.android.minetopin.activity.MainTab;
import com.android.minetopin.enums.EJumpStatus;
import com.android.minetopin.fragment.BaseLazyFragment;
import com.android.minetopin.model.MainTabData;
import com.android.minetopin.model.detail.Banner;
import com.android.minetopin.model.detail.BrandGoodsListData;
import com.android.minetopin.model.group.MainThematicActivity_Insert;
import com.android.minetopin.model.member.SeaAmoyMain;
import com.android.minetopin.model.member.SeaAmoyMainCallback;
import com.android.minetopin.model.member.TopicGoodsData;
import com.android.minetopin.model.member.TopicGoodsDataCallback;
import com.android.minetopin.pojo.BannerUintPojo;
import com.android.minetopin.utils.ConstantsUrl;
import com.android.minetopin.utils.HttpUtils;
import com.android.minetopin.utils.JumpUtils;
import com.android.minetopin.utils.ObjectUtils;
import com.android.minetopin.view.group.VRefreshLayout;
import com.android.minetopin.view.group.ViewPagerIndicator;
import com.android.minetopin.view.recycleview.CustomLoadMoreView;
import com.android.minetopin.view.recycleview.CustomRecycleView;
import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.mcxtzhang.nestlistview.NestFullListView;
import com.mcxtzhang.nestlistview.NestFullListViewAdapter;
import com.mcxtzhang.nestlistview.NestFullViewHolder;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import okhttp3.Call;


/**
 * Created by Administrator on 2017/7/7.
 */

public class Fragment_SAMain_TabList extends BaseLazyFragment implements BaseQuickAdapter.RequestLoadMoreListener {


    @BindView(R.id.listView)
    CustomRecycleView mRecyclerView;
    @BindView(R.id.swipe_refresh_layout)
    VRefreshLayout mRefreshLayout;
    @BindView(R.id.click_resetnetwork)
    LinearLayout clickResetnetwork;
    @BindView(R.id.progress)
    RelativeLayout progress;
    @BindView(R.id.no_data_tv)
    TextView noDataTv;
    @BindView(R.id.no_data)
    RelativeLayout noData;
    @BindView(R.id.progress_loading)
    FrameLayout progressLoading;
    private View rootView;
    private AdaptList adapter;
    private LayoutInflater inflater;
    private boolean networkConnected;
    private FragmentActivity mcontext;
    private int page=1;
    private ArrayList<Banner.Bannerdata> Bannerlist = new ArrayList<>();
    private ViewPager bannerpager;
    private ViewPagerIndicator viewPagerIndicator1;
    private BrandGoodsListData branddata = new BrandGoodsListData();
    private ArrayList<TopicGoodsData.DataBean.ListBean> listdata = new ArrayList<>();
    private ArrayList<MainThematicActivity_Insert.DataBean.ListBean> ta_insert = new ArrayList<>();
    private NestFullListView sort_grid1;
    private NestFullListView sort_grid2;
    private NestFullListView country_grid1;
    private NestFullListView country_grid2;
    private ArrayList<MainTabData> griddata1 = new ArrayList<>();
    private ArrayList<MainTabData> griddata2 = new ArrayList<>();
    private ArrayList<MainTabData> griddata3 = new ArrayList<>();
    private ArrayList<MainTabData> griddata4 = new ArrayList<>();
    private ImageView thematic1;
    private ImageView thematic2;
    private ImageView thematic3;
    private ImageView thematic4;
    private static final String ARG_PARAM1 = "param1";
    private View fragment_head;
    private View inflate;
    private TextView refresh_textView;


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
            page=1;
        }
    }

    public static Fragment_SAMain_TabList newInstance() {
        Fragment_SAMain_TabList fragment = new Fragment_SAMain_TabList();
        Bundle args = new Bundle();
        fragment.setArguments(args);
        return fragment;
    }


    @Override
    protected void initPrepare() {
            ReFreshData();
    }

    @Override
    protected void onInvisible() {

    }
    @Override
    protected void initData() {


        networkConnected = ObjectUtils.isNetworkConnected(getActivity());
     //   if (networkConnected) {
            page = 1;
                //getMianThematic_Insert();
                GetSAMAIN();
            GetListData(page);
//        } else {
//
//            ObjectUtils.GetDataNet(clickResetnetwork, progress, 4);
//        }

    }
    private LinearLayoutManager mLayoutManager;
    private GridLayoutManager mGridLayoutManager;
    @Override
    protected View initView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        this.inflater = inflater;
        networkConnected = ObjectUtils.isNetworkConnected(getActivity());
        rootView = inflater.inflate(R.layout.layout_recycle_samainrefresh, container, false);
        ButterKnife.bind(this, rootView);
        mcontext = getActivity();
   //     mainTopBg.setVisibility(View.GONE);
        initUI();
        return rootView;
    }
    /**
     * 轮播图销毁开启
     */

    @Override
    public void onStart() {
        super.onStart();
            viewPagerIndicator1.setVisible(true);

    }


    @Override
    public void onPause() {
        super.onPause();
            viewPagerIndicator1.setVisible(false);
    }
    private void initUI() {
            //轮播图
             fragment_head = inflater.inflate(R.layout.samain_frament3_head_banner, null, false);
            bannerpager = (ViewPager) fragment_head.findViewById(R.id.bannerpager_fragment);
            viewPagerIndicator1 = (ViewPagerIndicator) fragment_head.findViewById(R.id.viewPagerIndicator1);
            viewPagerIndicator1.autoScroll(getFragmentManager(), bannerpager, 1);
            //分类+快报 包括国家馆
            sort_grid1 = (NestFullListView) fragment_head.findViewById(R.id.main_fragment_grid_sort1);
            sort_grid2 = (NestFullListView) fragment_head.findViewById(R.id.main_fragment_grid_sort2);
            country_grid1 = (NestFullListView) fragment_head.findViewById(R.id.country_grid1);
        country_grid2 = (NestFullListView) fragment_head.findViewById(R.id.country_grid2);
            sort_grid1.setAdapter(new NestFullListViewAdapter<MainTabData>(R.layout.item_grid_fragment_sort, griddata1) {
                @Override
                public void onBind(int position, MainTabData testBean, NestFullViewHolder holder) {
                    holder.setText(R.id.item_grid_fragment_sort_tv, testBean.getName());
                    ObjectUtils.photo(mcontext, testBean.getImg(), ((ImageView) holder.getView(R.id.item_grid_fragment_sort_img)));
                }
            });
            sort_grid2.setAdapter(new NestFullListViewAdapter<MainTabData>(R.layout.item_grid_fragment_sort, griddata2) {
                @Override
                public void onBind(int position, MainTabData testBean, NestFullViewHolder holder) {
                    holder.setText(R.id.item_grid_fragment_sort_tv, testBean.getName());
                    ObjectUtils.photo(mcontext,testBean.getImg(), ((ImageView) holder.getView(R.id.item_grid_fragment_sort_img)));

                }
            });
            country_grid1.setAdapter(new NestFullListViewAdapter<MainTabData>(R.layout.item_grid_fragment_sort, griddata3) {
                @Override
                public void onBind(int position, MainTabData testBean, NestFullViewHolder holder) {
                    holder.setText(R.id.item_grid_fragment_sort_tv, testBean.getName());
                    ObjectUtils.photo(mcontext,testBean.getImg(), ((ImageView) holder.getView(R.id.item_grid_fragment_sort_img)));

                }
            });
        country_grid2.setAdapter(new NestFullListViewAdapter<MainTabData>(R.layout.item_grid_fragment_sort, griddata4) {
            @Override
            public void onBind(int position, MainTabData testBean, NestFullViewHolder holder) {
                holder.setText(R.id.item_grid_fragment_sort_tv, testBean.getName());
                ObjectUtils.photo(mcontext,testBean.getImg(), ((ImageView) holder.getView(R.id.item_grid_fragment_sort_img)));

            }
        });
            sort_grid1.setOnItemClickListener(new MainSortStartTo(griddata1));
            sort_grid2.setOnItemClickListener(new MainSortStartTo(griddata2));
            country_grid1.setOnItemClickListener(new MainSortStartTo(griddata3));
            country_grid2.setOnItemClickListener(new MainSortStartTo(griddata4));
            //四个专题
            thematic1 = (ImageView) fragment_head.findViewById(R.id.thematic1);
            thematic2 = (ImageView) fragment_head.findViewById(R.id.thematic2);
            thematic3 = (ImageView) fragment_head.findViewById(R.id.thematic3);
            thematic4 = (ImageView) fragment_head.findViewById(R.id.thematic4);
        mRecyclerView.removeAllViewsInLayout();
        mRecyclerView.removeAllViews();
        adapter = new AdaptList(mcontext,ta_insert, null, "0");
        adapter.addHeaderView(fragment_head);
        adapter.setLoadMoreView(new CustomLoadMoreView());
        adapter.setOnLoadMoreListener(this, mRecyclerView);
        mLayoutManager = new LinearLayoutManager(mcontext);
        mRecyclerView.setLayoutManager(mLayoutManager);
        mRecyclerView.setAdapter(adapter);
        mRecyclerView.GetToTop((ImageView) rootView.findViewById(R.id.top), 0);
        adapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter1, View view, int position) {
                ObjectUtils.ToDetailActivity(mcontext, 1, adapter.getItem(position).getId(), "");
            }
        });
        adapter.setOnItemChildClickListener(new BaseQuickAdapter.OnItemChildClickListener() {
            @Override
            public boolean onItemChildClick(BaseQuickAdapter adapter1, View view, int position) {
                switch (view.getId()) {
                    case R.id.bdmain_iv:
                        break;
                }
                return false;
            }
        });

    }


    /**
     * 分类跳转
     */

    class MainSortStartTo implements NestFullListView.OnItemClickListener {
        ArrayList<MainTabData> griddata;

        public MainSortStartTo(ArrayList<MainTabData> griddata) {
            this.griddata = griddata;
        }

        @Override
        public void onItemClick(NestFullListView nestFullListView, View view, int position) {

            MainTabData pojo  = griddata.get(position);
            BannerUintPojo Apojo  = new BannerUintPojo();
            Apojo.return_type = pojo.getAnurl();
            Apojo.title = pojo.getName();
            Apojo.id =  griddata.get(position).getId();
            if(JumpUtils.jumpToEveryWhere(getActivity(), Apojo, Fragment_SAMain_TabList.this))return;


            switch (griddata.get(position).getName()) {
                case "1":
                    Intent intent_tab = new Intent(mcontext, MainTab.class);
                    intent_tab.putExtra(ConstantsUrl.INTENT_KEY.MAIN_GROUP_TAB_SORT_SHOW_ID, 0);
                    intent_tab.putExtra(ConstantsUrl.INTENT_KEY.MAIN_GROUP_TAB_SORT_SHOW_TYPE, 3);
                    startActivity(intent_tab);
                    break;
                case "2":
                    Intent intent_bd = new Intent(mcontext, BaseObject.class);
                    intent_bd.putExtra(ConstantsUrl.INTENT_KEY.MAIN_GROUP_OBJEXT_SORT_TITLE,"品牌折扣");
                    startActivity(intent_bd);
                    break;
                case "3":
                    Intent intent_tabs = new Intent(mcontext, MainTab.class);
                    intent_tabs.putExtra(ConstantsUrl.INTENT_KEY.MAIN_GROUP_TAB_SORT_SHOW_ID, 0);
                    intent_tabs.putExtra(ConstantsUrl.INTENT_KEY.MAIN_GROUP_TAB_SORT_SHOW_TYPE, 8);
                    startActivity(intent_tabs);
                    break;
                case "5":
                    Intent intent_address = new Intent(mcontext, BaseObject.class);
                    intent_address.putExtra(ConstantsUrl.INTENT_KEY.MAIN_GROUP_OBJEXT_SORT_TITLE, griddata.get(position).getName());
                    startActivity(intent_address);
                    break;
                case "9":
                    Intent intentss = new Intent (mcontext,BaseObject.class);
                    intentss.putExtra(ConstantsUrl.INTENT_KEY.MAIN_GROUP_OBJEXT_SORT_TITLE,"店铺街");
                    startActivity(intentss);
                    break;
                case "美国馆":
                case "德国馆":
                case "港台馆":
                case "美国":
                case "德国":
                case "港台":
                case "澳州":
                case "新西兰":
                case "英国":
                case "日本":
                case "荷兰":
                case "法国":
                case "韩国":
                case "新加坡":
                case "意大利":
                case "其他":
                    Intent intent_country = new Intent(mcontext, BaseObject.class);
                    intent_country.putExtra(ConstantsUrl.INTENT_KEY.MAIN_GROUP_OBJEXT_SORT_TITLE,"国家馆");
                    intent_country.putExtra(ConstantsUrl.INTENT_KEY.MAIN_GROUP_OBJEXT_SORT_NEED_ID,griddata.get(position).getId());
                    intent_country.putExtra("country_name",griddata.get(position).getName());
                    startActivity(intent_country);
                    break;
                default:
//                    Intent intent = new Intent(mcontext, MainRecommendType.class);
//                    intent.putExtra(ConstantsUrl.INTENT_KEY.MAIN_GROUP_SORT_SHOW_TITLE, griddata.get(position).getName());
//                    startActivity(intent);

                    if(pojo.getAnurl()!=null) {
                        Intent intent = new Intent(mcontext, MainRecommendType.class);
                        intent.putExtra(ConstantsUrl.INTENT_KEY.MAIN_GROUP_SORT_SHOW_TITLE, griddata.get(position).getName());
                        intent.putExtra(ConstantsUrl.INTENT_KEY.MAIN_GROUP_SORT_SHOW_LINK, griddata.get(position).getId());

                        intent.putExtra(ConstantsUrl.INTENT_KEY.return_type, pojo.getAnurl());
                        startActivity(intent);
                    }
                    break;
            }
        }
    }





    private void ReFreshData() {
        if (mRefreshLayout != null) {

            mRefreshLayout.setBackgroundColor(Color.TRANSPARENT);
            mRefreshLayout.setAutoRefreshDuration(400);
            mRefreshLayout.setRatioOfHeaderHeightToReach(1.5f);
            mRefreshLayout.addOnRefreshListener(new VRefreshLayout.OnRefreshListener() {
                @Override
                public void onRefresh() {
                    networkConnected = ObjectUtils.isNetworkConnected(mcontext);
                    if (networkConnected) {
                        mRefreshLayout.postDelayed(new Runnable() {
                            @Override
                            public void run() {
                                mRefreshLayout.refreshComplete();
                                page = 1;
                                    //getMianThematic_Insert();
                                    GetSAMAIN();
                                GetListData(page);
                            }
                        }, 1000);
                    } else {
                        ObjectUtils.toast(mcontext, "网络连接出现异常");
                    }
                }
            });
        }


    }

    @OnClick(R.id.click_resetnetwork_refresh)
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.click_resetnetwork_refresh:
                ObjectUtils.GetDataNet(clickResetnetwork, progress, 3);
                page = 1;
                    //getMianThematic_Insert();
                    GetSAMAIN();
                GetListData(page);
                break;

        }
    }


    @Override
    public void onLoadMoreRequested() {
        page++;
        GetListData(page);
    }
//    /**
//     * 专题活动插入信息
//     */
//    private void getMianThematic_Insert()
//    {
//        String address ="http://192.168.1.47/api/" + ConstantsUrl.MAINTHMATIC_INSERT;
//        HashMap<String,String>  map = new HashMap<>();
//        map.put("posid","1");
//        HttpUtils.get(address, map, new MainThematicActivity_InsertCallback() {
//            @Override
//            public void onError(Call call, Exception e, int id) {
//
//            }
//
//            @Override
//            public void onResponse(MainThematicActivity_Insert response, int id) {
//                ta_insert.clear();
//                if (response.getData() != null && response.getData().getList().size() > 0) {
//                    ta_insert.addAll(response.getData().getList());
//                    mRecyclerView.setLayoutManager(mLayoutManager);
//                    mRecyclerView.setAdapter(adapter);
//
//                }
//
//
//            }
//        });
//    }
    private void GetSAMAIN()
    {

        networkConnected = ObjectUtils.isNetworkConnected(getActivity());
        String address = ConstantsUrl.domain + ConstantsUrl.NATIONLISTDATA;
        if (networkConnected) {
            HttpUtils.get(address,null, new SeaAmoyMainCallback() {

                @Override
                public void onError(Call call, Exception e, int id) {
                    ObjectUtils.GetDataNet(clickResetnetwork, progress, 2);
                }

                @Override
                public void onResponse(SeaAmoyMain response, int id) {
                    griddata1.clear();

                    griddata2.clear();
                    griddata3.clear();
                    griddata4.clear();
                    ObjectUtils.GetDataNet(clickResetnetwork, progress, 1);
                    if (response.getCode() == 0) {
                        ObjectUtils.GetDataNet(clickResetnetwork, progress, 1);
                        Bannerlist.clear();
                        for (int i = 0; i < response.getData().getAd_list().size(); i++) {
                            Bannerlist.add(new Banner.Bannerdata());
                            Bannerlist.get(i).setThumb(response.getData().getAd_list().get(i).getPath());
                        }
                        viewPagerIndicator1.setViewPager(Bannerlist);
                        viewPagerIndicator1.setNotifyDataSetChanged();
                        int size1, size2, size3, size4;
                        if (response.getData().getNav_top() != null) {
                            if (response.getData().getNav_top().size() > 5) {
                                size1 = 5;
                                size2 = response.getData().getNav_top().size();

                            } else {
                                size1 = response.getData().getNav_top().size();
                                size2 = 0;
                            }
                            if (response.getData().getCountry_list().size() > 4) {
                                size3 = 4;
                                size4 = response.getData().getCountry_list().size();
                            } else {
                                size3 = response.getData().getCountry_list().size();
                                size4 = 0;
                            }
                            String return_type = null;
                            for (int i = 0; i < size1; i++) {
                                return_type = response.getData().getNav_top().get(i).getAnurl();
                                if (return_type == null) {
                                    // return_type =  EJumpStatus.EnumImport.getRegmatch();
                                }
                                griddata1.add(new MainTabData(response.getData().getNav_top().get(i).getName(), i + 1 + "", response.getData().getNav_top().get(i).getImg(), return_type));
                            }
                            for (int i = 5; i < size2; i++) {
                                return_type = response.getData().getNav_top().get(i).getAnurl();
                                if (return_type == null) {
                                    //  return_type =  EJumpStatus.EnumImport.getRegmatch();
                                }
                                griddata2.add(new MainTabData(response.getData().getNav_top().get(i).getName(), i + 1 + "", response.getData().getNav_top().get(i).getImg(), return_type));
                            }
                            for (int i = 0; i < size3; i++) {
                                return_type = EJumpStatus.ECountry.getRegmatch();
                                if (return_type == null) {

                                }
                                griddata3.add(new MainTabData(response.getData().getCountry_list().get(i).getCatname(), response.getData().getCountry_list().get(i).getId(), response.getData().getCountry_list().get(i).getThumb(), return_type));
                            }
                            for (int i = 4; i < size4; i++) {
                                return_type = EJumpStatus.ECountry.getRegmatch();
                                if (return_type == null) {

                                }
                                griddata4.add(new MainTabData(response.getData().getCountry_list().get(i).getCatname(), response.getData().getCountry_list().get(i).getId(), response.getData().getCountry_list().get(i).getThumb(), return_type));
                            }

                            sort_grid1.updateUI();
                            sort_grid2.updateUI();
                            country_grid1.updateUI();
                            country_grid2.updateUI();
                        }
                        ObjectUtils.photo2(mcontext, response.getData().getAd_list_topic().get(0).getPath(), thematic1);
                        ObjectUtils.photo2(mcontext, response.getData().getAd_list_topic().get(1).getPath(), thematic2);
                        ObjectUtils.photo2(mcontext, response.getData().getAd_list_topic().get(2).getPath(), thematic3);
                        ObjectUtils.photo2(mcontext, response.getData().getAd_list_topic().get(3).getPath(), thematic4);
                    } else {
                        noData.setVisibility(View.VISIBLE);
                        noDataTv.setVisibility(View.VISIBLE);
                        noDataTv.setText(response.getMsg());
                    }
                }
            });
        } else {
            ObjectUtils.toast(getActivity(), "网络连接出现异常");
        }
    }

    private void GetListData(final int page) {
        networkConnected = ObjectUtils.isNetworkConnected(mcontext);
        String address = ConstantsUrl.domain + ConstantsUrl.BIDCOMPETITION_ALIST;
        HashMap<String,String> map = new HashMap<>();
        map.put("page",page+"");
        map.put("typeid","3");
        if (networkConnected) {
            HttpUtils.get(address,map, new TopicGoodsDataCallback() {

                @Override
                public void onError(Call call, Exception e, int id) {
                    ObjectUtils.GetDataNet(clickResetnetwork, progress, 2);
                }

                @Override
                public void onResponse(TopicGoodsData response, int id) {
                    ObjectUtils.GetDataNet(clickResetnetwork, progress, 1);

                    if (response.getCode() == 0) {
                        listdata = new ArrayList();
                        if (response.getData().getList() != null && response.getData().getList().size() > 0) {
                            listdata.addAll(response.getData().getList());
                            if (page == 1) {
                                adapter.setNewData(listdata);
                                mRecyclerView.setAdapter(adapter);
                            } else {
                                adapter.addData(listdata);
                                mRecyclerView.setAdapter(adapter);
                                adapter.loadMoreComplete();
                            }
                        }
                        else
                        {
                            adapter.loadMoreEnd();
                        }
                    } else {
                        noData.setVisibility(View.VISIBLE);
                        noDataTv.setVisibility(View.VISIBLE);
                        noDataTv.setText(response.getMsg());
                    }
                }
            });
        } else {
            if (page == 1) {
                ObjectUtils.GetDataNet(clickResetnetwork, progress, 2);
            }
            ObjectUtils.toast(mcontext, "网络连接出现异常");
            adapter.loadMoreFail();
        }
    }


    public class AdaptList extends BaseMultiItemQuickAdapter<TopicGoodsData.DataBean.ListBean, BaseViewHolder> {
        private String type;
        private FragmentActivity mcontext;
        private ArrayList<MainThematicActivity_Insert.DataBean.ListBean> ta_insert;
        private int limitposition;
        public AdaptList(Context context, ArrayList<TopicGoodsData.DataBean.ListBean> data, String type){
            super(data);
            addItemType(ConstantsUrl.BRANDDISCOUNTMAINITEMTYPE, R.layout.item_list_main);
        }
        public AdaptList(FragmentActivity context, ArrayList<MainThematicActivity_Insert.DataBean.ListBean> ta_insert, List<TopicGoodsData.DataBean.ListBean> data, String type) {
            super(data);
            //  this.datasize = data.size();
            this.mcontext = context;
            this.type = type;
            this.ta_insert = ta_insert;
            addItemType(ConstantsUrl.BRANDDISCOUNTMAINITEMTYPE, R.layout.item_list_main);
        }
        @Override
        protected void convert(BaseViewHolder holder, final TopicGoodsData.DataBean.ListBean mainlistdata) {
            switch (holder.getItemViewType()) {
                case ConstantsUrl.BRANDDISCOUNTMAINITEMTYPE:
                    ((TextView) holder.getView(R.id.item_list_sort_aa_before)).getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);
                    ObjectUtils.photo2(mContext, mainlistdata.getThumb(), ((ImageView) holder.getView(R.id.main_list_item_image)));
                    holder.setText(R.id.main_list_item_tuannumber, mainlistdata.getTeam_num() + "人团");
                    holder.setText(R.id.ll_start_soon_num, mainlistdata.getTeam_num() + "人团");
                    holder.setText(R.id.ll_free_num, mainlistdata.getTeam_num() + "人团");
                    holder.setText(R.id.main_list_item_title, mainlistdata.getName());
                    if ( mainlistdata.getSell_num()!=null&& !mainlistdata.getSell_num().equals("")){
                        holder.setText(R.id.main_list_item_alltuannumber2, "已团" + mainlistdata.getSell_num() + "件");
                    }else{
                        holder.setVisible(R.id.main_list_item_alltuannumber2, false);
                    }
                    String price1 = mainlistdata.getTeam_price();
                    SpannableString msp = new SpannableString("￥" + price1);
                    msp.setSpan(new AbsoluteSizeSpan(13, true), 0, 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
                    holder.setText(R.id.main_list_item_money_after, msp);
                    /**
                     * 插入专题活动
                     */
//                        final int taposition = holder.getAdapterPosition() + 1;
//                        limitposition = 4 * ta_insert.size();
//                        if (mcontext instanceof FragmentActivity) {
//                            if (taposition % 4 == 0 && taposition <= limitposition) {
//
//                                holder.getView(R.id.ll_tainsert).setVisibility(View.VISIBLE);
//                                holder.getView(R.id.progress_hot).setVisibility(View.INVISIBLE);
//                                TextView more_tv = (TextView) holder.getView(R.id.more_tv);
//                                //水平滚动列表
//                                NestFullListView tabrow = (NestFullListView) holder.getView(R.id.grid);
//                                //        //动态设置选项卡宽度，超过2个可以滑动查看
//                                DisplayMetrics metrics = new DisplayMetrics();
//                                mcontext.getWindowManager().getDefaultDisplay().getMetrics(metrics);
//                                final LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(metrics.widthPixels / 2, LinearLayout.LayoutParams.MATCH_PARENT);
//                                tabrow.setAdapter(new NestFullListViewAdapter<MainThematicActivity_Insert.DataBean.ListBean.ApplyBean>(R.layout.list_main_hor_adapter, ta_insert.get(taposition / 4 - 1).getApply_list()) {
//                                    @Override
//                                    public void onBind(int position, MainThematicActivity_Insert.DataBean.ListBean.ApplyBean testBean, NestFullViewHolder holder) {
//                                        (holder.getView(R.id.item_grid_detail_like_ll)).setLayoutParams(params);
//                                        ((TextView) holder.getView(R.id.item_grid_detail_like_number_before)).getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG | Paint.ANTI_ALIAS_FLAG);
//                                        String price1 = testBean.getTeam_price();
//                                        SpannableString msp = new SpannableString("￥" + price1);
//                                        msp.setSpan(new AbsoluteSizeSpan(10, true), 0, 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
//                                        ((TextView) holder.getView(R.id.item_grid_detail_like_number_after)).setText(msp);
//                                        holder.setText(R.id.item_grid_detail_like_number_before, "￥" + testBean.getPrice());
//                                        holder.setText(R.id.item_grid_detail_like_title, testBean.getName());
//                                        ObjectUtils.photo2(mcontext, testBean.getImg_cover(), ((ImageView) holder.getView(R.id.item_grid_detail_like_img)));
//
//                                    }
//                                });
//
//                                tabrow.setOnItemClickListener(new NestFullListView.OnItemClickListener() {
//                                    @Override
//                                    public void onItemClick(NestFullListView nestFullListView, View view, int pos) {
//                                        // ObjectUtils.ToDetailActivity(mcontext, 1, ta_insert.get(taposition / 4 - 1).getApply_list().get(pos).getSid(), "");
//                                    }
//                                });
//                                more_tv.setOnClickListener(new View.OnClickListener() {
//                                    @Override
//                                    public void onClick(View view) {
//                                        Intent intent = new Intent(mcontext, BaseObject.class);
//                                        intent.putExtra(ConstantsUrl.INTENT_KEY.MAIN_GROUP_OBJEXT_SORT_NEED_ID, ta_insert.get(taposition / 3 - 1).getId());
//                                        intent.putExtra(ConstantsUrl.INTENT_KEY.MAIN_GROUP_OBJEXT_SORT_TITLE, "专题活动");
//                                        mcontext.startActivity(intent);
//                                    }
//                                });
//
//                            } else {
//                                holder.getView(R.id.ll_tainsert).setVisibility(View.GONE);
//                            }
//                    }
                    break;
            }
        }
    }
}
